package com.yanggu.mapreduce.topN;

import lombok.Data;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2020/2/8 21:24
 * @description:
 */
@Data
public class FlowBean implements WritableComparable<FlowBean> {

    private String phone;

    private Integer upFlow;

    private Integer downFlow;

    private Integer sumFlow;

    @Override
    public int compareTo(FlowBean flowBean) {
        return flowBean.getSumFlow() - this.sumFlow;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(this.phone);
        out.writeInt(this.upFlow);
        out.writeInt(this.downFlow);
        out.writeInt(sumFlow);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.phone = in.readUTF();
        this.upFlow = in.readInt();
        this.downFlow = in.readInt();
        this.sumFlow = in.readInt();
    }

    @Override
    public String toString() {
        return phone + '\t' + upFlow + "\t" + downFlow + "\t" + sumFlow;
    }
}
